package com.api.config;

import lombok.Data;

import java.util.function.Supplier;

/**
 * @Description: 描述
 * @Author: yangshfieng
 * @CreateDate: 2023/9/22
 */

@Data
public class MyException extends RuntimeException implements Supplier<MyException> {

    private Integer code;

    /**
     * 通过错误消息创建异常对象
     * @param message
     */
    public MyException(String message) {
        super(message);
        this.code = 500;
    }

    /**
     * 通过状态码和错误消息创建异常对象
     * @param message
     * @param code
     */
    public MyException(Integer code,String message) {
        super(message);
        this.code = code;
    }

    @Override
    public String toString() {
        return "MyException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }

    @Override
    public MyException get() {
        return new MyException("操作失败");
    }
}
